package rhinestone.Model;

import java.util.HashMap;

/**
 * The container of all discounts.
 *
 * @author Asido
 * @version 2010.12.16
 */
public class DiscountContainer {
	private HashMap<String, Discount> discounts;
	private static DiscountContainer instance;

	/**
	 * Private constructor which initializes the instance variables.
	 */
	private DiscountContainer() {
		discounts = new HashMap<String, Discount>();
	}

	/**
	 * Singleton pattern. Return an object of this container.
	 *
	 * @return The object of this container.
	 */
	public static DiscountContainer getInstance() {
		if(instance == null)
			instance = new DiscountContainer();
		return instance;
	}

	/**
	 * Adds the discount to the database.
	 * @param name The name of the discount.
	 * @param discount The discount to be added.
	 */
	public void addDiscount(String name, Discount discount) {
		discounts.put(name, discount);
	}

	/**
	 * Finds and return a discount witch is stored by the provided name.
	 *
	 * @param name Name of the discount.
	 * @return The discount (null if not found).
	 */
	public Discount getDiscount(String name) {
		return discounts.get(name);
	}
}
